# Utility to capture ARP packets using scapy
# Usage: sudo python sniff.py <OUTPUT FILE> <DURATION SECONDS>

import sys
import scapy.all

#Entry point
if __name__ == '__main__':

    #Get first argument as output file
    output=sys.argv[1]
    #Get second argument as sniffing duration time
    time=int(sys.argv[2])

    #Show parameters
    print "Capturando paquetes ARP por", time, "segundos en el archivo:", output

    #sniff
    result = scapy.all.sniff(filter = "arp", timeout = time)

    #write result if captured 1 packet or more
    resultCount = len(result);
    if resultCount > 0:
        scapy.all.wrpcap(output, result)

    #show result summary
    print "Paquetes capturados:", resultCount

